#!/usr/bin/env python3
import re

def fix_cpp_file(file_path):
    """修复C++文件中的语法错误"""
    with open(file_path, 'r', encoding='utf-8') as f:
        content = f.read()

    # 修复注释引起的语法错误
    # 修复 if (!// comment) 形式的错误
    content = re.sub(r'if\s*\(\s*!\s*//[^)]*\)\s*\{[^}]*\}', '// 已移除ExportStateManager检查', content, flags=re.DOTALL)

    # 修复 if (// comment) 形式的错误
    content = re.sub(r'if\s*\(\s*//[^)]*\)\s*\{[^}]*\}', '// 已移除ExportStateManager检查', content, flags=re.DOTALL)

    # 修复其他语法错误模式
    content = re.sub(r'//\s*m_exportStateManager\s*\[已移除\]->\w+\(\)', 'false', content)
    content = re.sub(r'//\s*m_exportStateManager\s*\[已移除\]', 'nullptr', content)

    # 修复 static_cast 中的注释
    content = re.sub(r'static_cast<int>\(//[^)]*\)', '0', content)

    with open(file_path, 'w', encoding='utf-8') as f:
        f.write(content)

if __name__ == '__main__':
    fix_cpp_file('/Users/ethan/Codes/longimagereader/statusbarmanager.cpp')
    print("语法修复完成")